package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.comment.AdditionalComment;
import com.qingcheng.service.comment.AdditionalCommentService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comment")
public class AdditionalCommentController {

    @Reference
    private AdditionalCommentService additionalCommentService;

    /**
     * 追加评论
     * @param additionalComment
     * @return
     */
    @PostMapping("/addAdditional")
    public Result addAdditional(@RequestBody AdditionalComment additionalComment){

        String username = SecurityContextHolder.getContext().getAuthentication().getName();

        if (additionalComment.getCommentId() == null){
            return new Result(1,"参数错误");
        }

        if (additionalComment.getContent() == null){
            return new Result(1,"参数错误");
        }

        additionalCommentService.addAdditional(additionalComment,username);

        return new Result();
    }
}
